package cn.clwxy.gdz.dao;

import java.util.List;

import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import cn.clwxy.gdz.entity.AdminOrder;
import cn.clwxy.gdz.util.BaseDao;

public class AdminOrderDaoimp extends BaseDao implements AdminOrderDao {

	@Override
	public List<AdminOrder> getOrders(Integer pageNo) {
		String sql="select  o.orderId as id, o.Initiator ,o.studentId studentId,o.teacherId teacherId, " +
				"s.studentName as  studentName  ,t.teacherRealName as   teacherName ,o.orderBeginTime as startTime, " +
				"o.orderFinishTime as endTime , o.teachercomment as teacherComment ,o.studentcomment as studentComment, " +
				"o.isPay as isPay,o.price as price ,o.profit as profit " +
				" from `order` as o INNER JOIN student as s on o.studentId=s.studentId " +
				"INNER JOIN teacher as t on t.teacherId =o.teacherId  where o.isDelete=0 ORDER BY  isPay ASC,o.orderBeginTime  DESC, o.orderId DESC limit ?,15";
				return super.queryList(sql, new BeanListHandler<AdminOrder>(AdminOrder.class), (pageNo-1)*15);
	}

	@Override
	public Long getTotalCount() {
		String sql="select  count(o.orderId) \n" +
				" from `order` as o INNER JOIN student as s on o.studentId=s.studentId\n" +
				"INNER JOIN teacher as t on t.teacherId =o.teacherId where o.isDelete=0  ORDER BY o.orderBeginTime DESC";
		return super.queryColumn(sql, new ScalarHandler());
	}

	@Override
	/**
	 * �޸Ķ���״̬
	 */
	public int deal(Integer id,Double price) {
		String sql="update `order` set isPay=1 ,price=?, profit=? where orderId=? ";
		return super.update(sql, price,0.2*price,id);
	}
	 public static void main(String[] args) {
	AdminOrderDaoimp asd=new AdminOrderDaoimp();
	int orders = asd.deal(10000007,1212.0);
	System.out.println(orders);
	 }

	@Override
	public int delete(int id) {
	String sql="update  `order` set isDelete=1 where `order`.orderId=? ";
	return super.update(sql, id);
		
	}
}
